package cn.jingyuan.swan.uaa.web.config;

import cn.jingyuan.swan.cloud.mapping.ApiResourceScanHandler;
import cn.jingyuan.swan.cloud.mapping.SpringBootApiResourceScanHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor;
import org.springframework.security.oauth2.provider.authentication.TokenExtractor;

import java.util.ArrayList;
import java.util.List;

/**
 * Web 相关配置
 */
@Configuration
public class AppWebConfig {

    @Bean
    @ConditionalOnMissingBean(ApiResourceScanHandler.class)
    public ApiResourceScanHandler apiResourceScanHandler() {
        List<String> urls = new ArrayList<>();
        urls.add("/error");

        SpringBootApiResourceScanHandler mappingScan = new SpringBootApiResourceScanHandler();
        mappingScan.enableScan();
        mappingScan.addIgnoreScanUrls(urls);
        return mappingScan;
    }


    @Bean
    public TokenExtractor tokenExtractor() {
        return new BearerTokenExtractor();
    }

    // /** 令牌信息拓展 */
    // @Bean
    // public TokenEnhancer tokenEnhancer() {
    //     return new DefaultTokenEnhancer();
    // }

}
